<!DOCTYPE html>

<html>
<head>
  <title>pyoidc RP</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
  <form action="/repost_fragment" method="post">
    <input type="hidden" name="op_hash" value="{{ op_hash }}"/>
    <input type="hidden" name="url_fragment" id="url_fragment" value=""/>
  </form>

  <script type="text/javascript">
        /*
        * Returns object with all variables of the fragment identifier and their values.
        * http://example.com/path#var1=v1&var2=v2 -> {"var1": v1, "var2": v2}
        */
        function parseFragmentIdentifier() {
          var params = {};
          var e,
          a = /\+/g,  // Regex for replacing plus sign with a space
          r = /([^&;=]+)=?([^&;]*)/g, // Regex for finding each variable in the fragment identifier
          decode = function (s) {
            return decodeURIComponent(s.replace(a, " "));
          },
          fragment = location.href.split("#")[1];

          while (e = r.exec(fragment)) {
            params[decode(e[1])] = decode(e[2]);
          }

          return params;
        }

        fragmentIdentifier = parseFragmentIdentifier();
        console.log(fragmentIdentifier);
        document.getElementById("url_fragment").value = $.param(fragmentIdentifier);
        document.forms[0].submit()
    </script>
</body>
</html>
